package org.kgc.alanhealth.controller;

import org.kgc.alanhealth.entity.HospitalBill;
import org.kgc.alanhealth.entity.HospitalShoppingcart;
import org.kgc.alanhealth.service.OrderService;
import org.kgc.alanhealth.util.Result;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("order")
@CrossOrigin(origins = "*")
public class OrderController {

    @Autowired
    OrderService orderService;


    @PostMapping("add")
    public Result addOrder(@RequestBody HospitalBill hospitalBill){
        if(orderService.insert(hospitalBill)){

            return Result.success("订单生成成功");
        }else {
            return Result.error("订单生成失败");
        }

    }
    @PostMapping("select")
    public Result selectByStatus(@RequestBody HospitalBill bill){
        List<HospitalBill> list=orderService.selectByStatus(bill);
        if (list!=null&&!list.isEmpty()){
            return Result.success(list);
        }else{
            return Result.error("没有找到数据");
        }
    }
    @PostMapping("pay")
    public Result orderPay(@RequestBody HospitalBill bill){


        if(orderService.updateOrder(bill)){
            return Result.success("支付成功");
        }else {
            return Result.error("支付失败");
        }
    }


    @PostMapping("cancel")
    public Result orderCancel(@RequestBody HospitalBill bill){

        if(orderService.updateOrder1(bill)){
            return Result.success("已取消订单");
        }else {
            return Result.error("取消失败");
        }
    }

}
